//    Copyright (C) Kherty.  All rights reserved.
using System;
using OpenLS.Core.Serialization;
using OpenLS.Drawing.Serialization;

namespace OpenLS.Drawing
{
    public class NonVisualDrawingProperties : IOfficeXmlSerializable, IOfficeXmlSerializableAs
    {
        private string _name;
        private OfficeArtExtensionList extLst;

        public Hyperlink HyperlinkClick { get; set; }

        public string Name
        {
            get
            {
                if (_name == null)
                    _name = "";
                return _name;
            }
            set { _name = value; }
        }

        public int Id { get; set; }

        public string Description { get; set; }
        public string Title { get; set; }

        public bool Hidden { get; set; }

        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            ((IOfficeXmlSerializableAs) this).ReadXmlAs("cNvPr", context);
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            IOfficeXmlSerializableAs a = this;
            a.WriteXmlAs("cNvPr", context);
        }

        #endregion

        void IOfficeXmlSerializableAs.ReadXmlAs(string name, ReadContext context)
        {
            using (var c = context.Read(name))
            {
                Name = c.GetString("name");
                Id = c.GetInteger("id");
                Description = c.GetOptionalString("descr");
                Title = c.GetOptionalString("title");
                Hidden = c.GetOptionalBoolean("hidden", false);
                c.PassAttributes();
                ReadContext cc = c.SwitchNamespace(DrawingConstants.DrawingNamespaceUri, false);
                HyperlinkClick = cc.ReadOptionalElementAs<Hyperlink>("hlinkClick");
                HyperlinkHover = cc.ReadOptionalElementAs<Hyperlink>("hlinkHover");
                extLst = cc.ReadOptionalElement<OfficeArtExtensionList>("extLst");
            }
        }

        protected Hyperlink HyperlinkHover
        {
            get; set;
        }

        void IOfficeXmlSerializableAs.WriteXmlAs(string name, WriteContext context)
        {
            using (var c = context.Write(name))
            {
                c.SetString("name",Name);
                c.SetInteger("id", Id);
                c.SetOptionalString("descr", Description);
                c.SetOptionalString("title", Title);
                c.SetOptionalBoolean("hidden", Hidden, false);
                var cc = c.Switch(DrawingConstants.DrawingNamespace);
                cc.WriteOptionalElementAs(HyperlinkClick, "hlinkClick");
                cc.WriteOptionalElementAs(HyperlinkHover ,"hlinkHover");
                cc.WriteOptionalElement(extLst);
            }
        }
    }
}